package com.ruoyi.picture.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.picture.domain.Fam;
import com.ruoyi.picture.domain.Pauser;
import com.ruoyi.picture.mapper.PauserMapper;
import com.ruoyi.weixin.entity.PicUser;
import com.ruoyi.weixin.mapper.PicUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.picture.mapper.AcicturesMapper;
import com.ruoyi.picture.domain.Acictures;
import com.ruoyi.picture.service.IAcicturesService;

/**
 * 相册管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-15
 */
@Service
public class AcicturesServiceImpl implements IAcicturesService 
{
    @Autowired
    private AcicturesMapper acicturesMapper;

    @Autowired
    private PauserMapper pauserMapper;

    @Autowired
    PicUserMapper picUserMapper;

    @Override
    public int insertlist(Fam fam) {
        Acictures acictures = selectAcicturesById(fam.getId());
        if (acictures.getStatus().equals("0")){
            return 1;
        }else {
            int delete = picUserMapper.delete(new LambdaQueryWrapper<PicUser>().eq(PicUser::getPicturesId, fam.getId()));
            List<String> ids = fam.getIds();
            PicUser picUser = new PicUser();
            picUser.setPicturesId(fam.getId().intValue());
            for (String id : ids) {
                picUser.setId(null);
                picUser.setUserId(Integer.valueOf(id));
                picUserMapper.insert(picUser);
            }
        }
        return 0;
    }

    @Override
    public Acictures selectAcicturesById(Long id)
    {
        return acicturesMapper.selectAcicturesById(id);
    }

    /**
     * 查询相册管理列表
     * 
     * @param acictures 相册管理
     * @return 相册管理
     */
    @Override
    public List<Acictures> selectAcicturesList(Acictures acictures)
    {
        return acicturesMapper.selectAcicturesList(acictures);
    }

    /**
     * 新增相册管理
     * 
     * @param acictures 相册管理
     * @return 结果
     */
    @Override
    public int insertAcictures(Acictures acictures)
    {
        acictures.setCreateTime(DateUtils.getNowDate());
        return acicturesMapper.insertAcictures(acictures);
    }

    /**
     * 修改相册管理
     * 
     * @param acictures 相册管理
     * @return 结果
     */
    @Override
    public int updateAcictures(Acictures acictures)
    {
        acictures.setUpdateTime(DateUtils.getNowDate());
        return acicturesMapper.updateAcictures(acictures);
    }

    /**
     * 批量删除相册管理
     * 
     * @param ids 需要删除的相册管理主键
     * @return 结果
     */
    @Override
    public int deleteAcicturesByIds(Long[] ids)
    {
        return acicturesMapper.deleteAcicturesByIds(ids);
    }

    /**
     * 删除相册管理信息
     * 
     * @param id 相册管理主键
     * @return 结果
     */
    @Override
    public int deleteAcicturesById(Long id)
    {
        return acicturesMapper.deleteAcicturesById(id);
    }

    @Override
    public List<Pauser> userlist(Acictures acictures) {
        List<Pauser> pausers;
        if (acictures!=null){
            if (acictures.getStatus().equals("0")){
                  pausers = pauserMapper.selectPauserList(null);
            }else {
                pausers=pauserMapper.selectUserList(acictures);
            }
            return pausers;
        }
        return null;
    }


}
